package com.yawn.zerodefect.controller;

import com.yawn.zerodefect.controller.entity.RestResponse;
import com.yawn.zerodefect.service.UserService;
import org.activiti.engine.IdentityService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author Created by yawn on 2018-01-26 14:50
 */
@RestController
public class UserController {

    @Resource
    private IdentityService identityService;
    @Resource
    private UserService userService;

    @PostMapping("/user/add")
    public RestResponse add(@RequestBody com.yawn.zerodefect.entity.User user) {
        return userService.add(user);
    }

    @GetMapping("/user/delete")
    public RestResponse delete(String userId) {
        identityService.deleteUser(userId);
        return RestResponse.newInstance(1, "删除成功！");
    }

    @GetMapping("/user/update")
    public RestResponse update(com.yawn.zerodefect.entity.User user) {
        return null;
    }

    @GetMapping("/user/page")
    public RestResponse page(String userId, String name,
                             @RequestParam(name = "first", defaultValue = "0") int first,
                             @RequestParam(name = "size", defaultValue = "20") int size) {
        return userService.page(userId, name, first, size);
    }

    @GetMapping("/user/list")
    public RestResponse listByGroup(String groupId) {
        return userService.listByGroup(groupId);
    }

    @GetMapping("/group/list")
    public RestResponse listGroup() {
        return userService.listGroup();
    }

}
